import Pbf from "pbf"

var s: any = {}
s.read = (e: Pbf, t) => {
  return e.readFields(s._readField, { chunk: [], quantized_chunk: [] }, t)
}
s._readField = (e: number, t: any, s: Pbf) => {
  1 === e ? t.chunk.push(a.read(s, s.readVarint() + s.pos)) : 2 === e && t.quantized_chunk.push(d.read(s, s.readVarint() + s.pos))
}
s.write = function (e, t) {
  if (e.chunk) for (var s = 0; s < e.chunk.length; s++) t.writeMessage(1, a.write, e.chunk[s])
  if (e.quantized_chunk) for (s = 0; s < e.quantized_chunk.length; s++) t.writeMessage(2, d.write, e.quantized_chunk[s])
}
var r: any = {}
r.read = function (e, t) {
  return e.readFields(r._readField, { xyz: [], uv: [] }, t)
}
r._readField = function (e, t, s) {
  1 === e ? s.readPackedFloat(t.xyz) : 2 === e && s.readPackedFloat(t.uv)
}
r.write = function (e, t) {
  e.xyz && t.writePackedFloat(1, e.xyz), e.uv && t.writePackedFloat(2, e.uv)
}
var i: any = {}
i.read = function (e, t) {
  return e.readFields(i._readField, { faces: [] }, t)
}
i._readField = function (e, t, s) {
  1 === e && s.readPackedVarint(t.faces)
}
i.write = function (e, t) {
  e.faces && t.writePackedVarint(1, e.faces)
}
var a: any = {}
a.read = function (e: Pbf, t: number) {
  return e.readFields(a._readField, { vertices: null, faces: null, chunk_name: "", material_name: "" }, t)
}
a._readField = function (e, t, s) {
  1 === e
    ? (t.vertices = r.read(s, s.readVarint() + s.pos))
    : 2 === e
    ? (t.faces = i.read(s, s.readVarint() + s.pos))
    : 3 === e
    ? (t.chunk_name = s.readString())
    : 4 === e && (t.material_name = s.readString())
}
a.write = function (e, t) {
  e.vertices && t.writeMessage(1, r.write, e.vertices),
    e.faces && t.writeMessage(2, i.write, e.faces),
    e.chunk_name && t.writeStringField(3, e.chunk_name),
    e.material_name && t.writeStringField(4, e.material_name)
}
var o: any = {}
o.read = function (e, t) {
  return e.readFields(o._readField, { quantization: 0, translation: [], x: [], y: [], z: [] }, t)
}
o._readField = function (e, t, s) {
  1 === e
    ? (t.quantization = s.readFloat())
    : 2 === e
    ? s.readPackedFloat(t.translation)
    : 3 === e
    ? s.readPackedSVarint(t.x)
    : 4 === e
    ? s.readPackedSVarint(t.y)
    : 5 === e && s.readPackedSVarint(t.z)
}
o.write = function (e, t) {
  e.quantization && t.writeFloatField(1, e.quantization),
    e.translation && t.writePackedFloat(2, e.translation),
    e.x && t.writePackedSVarint(3, e.x),
    e.y && t.writePackedSVarint(4, e.y),
    e.z && t.writePackedSVarint(5, e.z)
}
var n: any = {}
n.read = function (e, t) {
  return e.readFields(n._readField, { name: "", quantization: 0, u: [], v: [] }, t)
}
n._readField = function (e, t, s) {
  1 === e ? (t.name = s.readString()) : 2 === e ? (t.quantization = s.readFloat()) : 3 === e ? s.readPackedSVarint(t.u) : 4 === e && s.readPackedSVarint(t.v)
}
n.write = function (e, t) {
  e.name && t.writeStringField(1, e.name),
    e.quantization && t.writeFloatField(2, e.quantization),
    e.u && t.writePackedSVarint(3, e.u),
    e.v && t.writePackedSVarint(4, e.v)
}
var h: any = {}
h.read = function (e, t) {
  return e.readFields(h._readField, { faces: [] }, t)
}
h._readField = function (e, t, s) {
  1 === e && s.readPackedSVarint(t.faces)
}
h.write = function (e, t) {
  e.faces && t.writePackedSVarint(1, e.faces)
}
var d: any = {}
d.read = function (e, t) {
  return e.readFields(
    d._readField,
    {
      chunk_name: "",
      material_name: "",
      vertices: null,
      uvs: [],
      faces: null
    },
    t
  )
}
d._readField = function (e, t, s) {
  1 === e
    ? (t.chunk_name = s.readString())
    : 2 === e
    ? (t.material_name = s.readString())
    : 3 === e
    ? (t.vertices = o.read(s, s.readVarint() + s.pos))
    : 4 === e
    ? t.uvs.push(n.read(s, s.readVarint() + s.pos))
    : 5 === e && (t.faces = i.read(s, s.readVarint() + s.pos))
}
d.write = function (e, t) {
  if (
    (e.chunk_name && t.writeStringField(1, e.chunk_name),
    e.material_name && t.writeStringField(2, e.material_name),
    e.vertices && t.writeMessage(3, o.write, e.vertices),
    e.uvs)
  )
    for (var s = 0; s < e.uvs.length; s++) t.writeMessage(4, n.write, e.uvs[s])
  e.faces && t.writeMessage(5, i.write, e.faces)
}

export default s
